package com.sushi.exception;

import com.sushi.exception.ServiceException;
import com.sushi.exception.SystemException;
import com.sushi.pojo.Option;
import com.sushi.pojo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionCatcher {

//    @ExceptionHandler
//    public Result catchException(Exception ex) {
//        System.out.println("有错，且拦到了");
//        return new Result(Option.EXCEPTION_TRY, null, "");
//    }
    @ExceptionHandler
    public Result catchSystemException(SystemException se) {
        System.out.println("捕获系统异常");
        return new Result(se.getOption(), null, se.getMessage());
    }
    @ExceptionHandler
    public Result catchServiceException(ServiceException se) {
        System.out.println("捕获业务异常");
        return new Result(se.getOption(), null, se.getMessage());
    }
}
